package com.jeesite.modules.dataScreen.web;

import com.jeesite.modules.dataScreen.entity.SsmContact;
import com.jeesite.modules.dataScreen.service.SsmContactService;
import com.jeesite.modules.dataScreen.web.dto.SsmContactUpdateDto;
import com.jeesite.modules.dataScreen.web.vo.Result;
import com.jeesite.modules.dataScreen.web.vo.ssmContact.SsmContactTreeVo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

@RestController
@RequestMapping("/ssmContact")
@Api(tags = "交通运行-通讯录")
public class SsmContactApi {

    @Resource
    private SsmContactService ssmContactService;

    @GetMapping
    @ApiOperation(value = "通讯录树形结构")
    public Result<List<SsmContactTreeVo>> buildTree() {
        return Result.OK(ssmContactService.buildTree());
    }

    @PostMapping
    @ApiOperation(value = "更新联系人分类")
    public Result<Void> updateSsmContact(@RequestBody @Validated SsmContactUpdateDto dto) {
        ssmContactService.updateSsmContact(dto);
        return Result.OK();
    }

    @GetMapping("/ejectment")
    @ApiOperation(value = "联系人移除分组")
    public Result<Void> ejectment(@RequestParam Integer id) {
        ssmContactService.ejectment(id);
        return Result.OK();
    }

    @GetMapping("/users")
    @ApiOperation(value = "列表")
    public Result<List<SsmContact>> users() {
        return Result.OK(ssmContactService.all());
    }

}
